Python Task 2

Task 2 - Create An GUI Calculator using Python

Image

Objective:

Create a basic calculator using Python and Tkinter that performs simple arithmetic operations like addition, subtraction, multiplication, and division.

Steps to Follow:

  1. Install Tkinter:
    • Ensure that Tkinter is installed. If needed, install it using the pip install tk command.

  2. Set Up the Main Window:
    • Create a main window for the calculator using Tkinter and configure its size and appearance (background color, title, etc.).

  3. Create the Entry Widget:
    • Add an entry widget that will be used to display user input and the result of the calculations.

  4. Define Functions for Button Actions:
    • A function that handles number and operator button clicks and updates the entry.
    • A function to clear the entry when the user presses the "C" button.
    • A function that evaluates the mathematical expression when the "=" button is pressed and displays the result in the entry.

  5. Create Number and Operator Buttons:
    • Create buttons for the digits (0–9), operators (+, -, *, /), and decimal point. These buttons will be placed in a grid layout.

  6. Add the "=" and "C" Buttons:
    • The "=" button should evaluate the current input and show the result.
    • The "C" button should clear the input field when pressed.

  7. Make the Layout Responsive:
    • Configure the grid layout so that the buttons resize properly when the window is resized.

  8. Run the Program:
    • Run the program and ensure the GUI is functioning properly.

Bonus Challenge:

Customize the calculator further by adding:

  • Memory functions (M+, M-, MR, MC)
  • Scientific operations like square root or exponentiation
  • Enhanced design with colors, icons, or improved layout

  • Use Python for your implementation.
  • Ensure your code is well-documented with comments explaining the functionality of each part.

  • We will be sharing a Google Form shortly to collect your code files.
  • Submit your code file through the provided Google Form link.
  • After submission, we will verify your task.

Social Medias

Loading...